%% Generates charts for the BOX in A4 summary

%% Housekeeping
close all
clear all

Dfontsize = 24;
fontsize = 18;

%% Load data
d = dbload('kalm_his.csv'); % Data from multivariate filter

%% Data range
range = qq(2007,1):qq(2013,1);

%% create a new pdf report
xx = report.new('');

%% Chart: Interest rate level
%h_xlabel = get(gca,'XLabel');
%set(h_xlabel,'FontSize',N); 
fh = figure();
plot(range,d.rn,'LineWidth',2,'color','r','LineStyle','-','marker','square','markersize',15,...
       'markeredgecolor','y','markerfacecolor',[.6,0,.6]);
hold on
plot(range,d.rn-d.e_rn,'LineWidth',2,'color','b','LineStyle','--');
h=legend('Actual','Fundamental','location','southEast',...
  'orientation','horizontal');
title('Figure 3. Actual Interbank Rate vs Model-based "Fundamental" Rate','FontSize',fontsize);
xlabel('[ Quarters ]','FontSize',fontsize);
ylabel('[ percent ]','FontSize',fontsize);
ylim([0 10]);
set(h,'Box','off','color','none','edgecolor','w','fontsize',fontsize);
set(gca,'fontsize',fontsize);
xx.userfigure('Interest rate',fh,'figuretrim',[40, 25, 40, 15]);

orient landscape
print(gcf,'-dpsc2','Intratelevel1.ps');
saveas(gcf,'Intratelevel1D','jpg');
%dummy = input('Adjust graph size and press Enter!');
%print(h,'-djpeg','interest rate level fig1.jpg');

%% Chart: Interest rate decomposition
%{
figure()
plot(range,d.rn,'LineWidth',3,'color','r','LineStyle','-','marker','square','markersize',12,...
       'markeredgecolor','y','markerfacecolor',[.6,0,.6]);
hold on
u = [d.S_rn_neutral d.S_infl d.S_gap d.S_e_rn ];
conbarplot(u,range,'');
hold on
plot(range,d.rn,'LineWidth',3,'color','r','LineStyle','-','marker','square','markersize',12,...
       'markeredgecolor','y','markerfacecolor',[.6,0,.6]);
h1=legend(({'Actual','Policy neutral rate','Expected inflation target misses', 'Demand pressures','Other factors'}));
title('Figure 4. Factors Explaining Interest Rate Changes','FontSize',fontsize);
colormap('bone');
%grid
%set(legend,'location','south','orientation','horizontal');
xlabel('[ Quarters ] ','FontSize',fontsize);
ylabel('[ percent, percentage points ]','FontSize',fontsize);
set([h1],'Box','off')
set(gca,'fontsize',fontsize);
print(gcf,'-dpsc2','Intratelevel_decomp.eps');
saveas(gcf,'Intratelevel_decomp','jpg');
%}

%% Chart: Output gap

figure();
u = [d.a1*d.lgdp_gap{-1}+(1-d.a1)*d.lgdp_gap{+1},-d.a2*d.mci, d.a3*d.lx_gdp_gap, d.e_lgdp_gap];
barcon(range,u,'colormap',colormap('bone'));
hold on;
plot(range,d.lgdp_gap,'LineWidth',3,'color','r','LineStyle','-','marker','square','markersize',12,...
       'markeredgecolor','y','markerfacecolor',[.6,0,.6]);
h = speclegend('Persistence and expected demand pressures','Monetary conditions', ...
  'Foreign demand','Other factors','Output Gap','location','northEast');
legend('left');
%grid
title('Figure 6. Ghana Output Gap and Factors Explaining Utilization of Economic Resources',...
  'FontSize',fontsize);
%set(legend,'location','south','orientation','horizontal');
xlabel('[ Quarters ] ','FontSize',fontsize);
ylabel('[ percent, percentage points ]','FontSize',fontsize);
set(h,'Box','off','color','none','edgecolor','w','fontsize',fontsize);
set(gca,'fontsize',fontsize);

orient landscape
print(gcf,'-dpsc2','outputgap_decomp.ps');
saveas(gcf,'outputgap_decomp','jpg');

%% Chart: Core Inflation

figure();
u = [d.b1*d.dot_cpi_x{-1}, (1 - d.b1)*d.e_dot_cpi_x, d.b2*d.rmc, d.e_dot_cpi_x];
barcon(range, u, 'colormap', colormap('bone'));
hold on;
plot(range,d.dot4_cpi_x,'LineWidth',3,'color','r','LineStyle','-','marker','square','markersize',12,...
       'markeredgecolor','y','markerfacecolor',[.6,0,.6]);
h = speclegend({'Inflation persistence', 'Inflation expectations' ,...
 'Demand pressures','Other factors', 'Actual'});
legend('left');
%grid
title('Figure 5. Factors Explaining Core Inflation','FontSize',fontsize);
%set(legend,'location','south','orientation','horizontal');
xlabel('[ Quarters ] ','FontSize',fontsize);
ylabel('[ percent, percentage points ]','FontSize',fontsize);
set(h,'Box','off','color','none','edgecolor','w','fontsize',fontsize);
set(gca,'fontsize',fontsize);

orient landscape
print(gcf,'-dpsc2','coreinflation_decomp.ps');
saveas(gcf,'coreinflation_decomp','jpg');

%% Chart: Headline inflation and target bands

x = [7	9
7	9
7	9
7	9
6	8
6	8
6	8
6	8
12.5	16.5
12.5	16.5
12.5	16.5
12.5	16.5
7.2	11.2
7.2	11.2
7.2	11.2
7.2	11.2
7	11
7	11
7	11
7	11
6.5	10.5
6.5	10.5
6.5	10.5
6.5	10.5
7   11];

figure();
plot(range,d.dot4_cpi,'LineWidth',3,'color',[0 93 126]/255,'LineStyle','-');
hold on
plot(range,d.dot4_cpi_x,'LineWidth',3,'color','r','LineStyle','-');
plot(range,d.dot4_cpi_food,'LineWidth',3,'color',[0 0.8 0],'LineStyle','--');
patch(dat2dec([range,fliplr(range)],'centre'),[x(:,2);x(end:-1:1,1)]',...
  [217 217 217]/255,'edgecolor','w');

h=legend({'Headline CPI Inflation','Core Inflation (excl. food and energy)',...
  'Food Inflation','Target Bands'});
legend('left');
title('Figure 1. Inflation in Ghana (2007Q1-2013Q1)','FontSize',fontsize);
set(h,'Box','off','color','none','edgecolor','w','fontsize',fontsize);

orient landscape
print(gcf,'-dpsc2','headinflation1.ps');
saveas(gcf,'headinflation1','jpg');

plot(range,d.dot4_cpi,'LineWidth',3,'color',[0 93 126]/255,'LineStyle','-');
hold on
plot(range,d.dot4_cpi_x,'LineWidth',3,'color','r','LineStyle','-');
plot(range,d.dot4_cpi_food,'LineWidth',3,'color',[0 0.8 0],'LineStyle','--');
ylabel('[ Percent ]','FontSize',fontsize);
xlabel('[ Quarters ]','FontSize',fontsize);
set(gca,'fontsize',fontsize);

orient landscape
print(gcf,'-dpsc2','headinflation2.ps');
saveas(gcf,'headinflation2','jpg');

%% Factors Explaining Core Inflation

figure();
plot(range,d.dot4_cpi_x,'LineWidth',3,'color','r','LineStyle','-','marker','square','markersize',12,...
       'markeredgecolor','y','markerfacecolor',[.6,0,.6]);
hold on
u = [d.b1*d.dot_cpi_x{-1}, (1 - d.b1)*d.e_dot_cpi_x, d.b2*d.rmc, d.e_dot_cpi_x];
barcon(range, u, 'colormap', colormap('bone'));
hold on
plot(range,d.dot4_cpi_x,'LineWidth',3,'color','r','LineStyle','-','marker','square','markersize',12,...
       'markeredgecolor','y','markerfacecolor',[.6,0,.6]);
h = speclegend({'Actual','Inflation persistence', 'Inflation expectations' , 'Demand pressures','Other factors'});
legend('left');
%grid
title('Factors Explaining Core Inflation','FontSize',fontsize);
%set(legend,'location','south','orientation','horizontal');
xlabel('[ Quarters ] ','FontSize',fontsize);
ylabel('[ percent, percentage points ]','FontSize',fontsize);
set(h,'Box','off','color','none','edgecolor','w','fontsize',fontsize);
set(gca,'fontsize',fontsize);

orient landscape
print(gcf,'-dpsc2','decompinflation2.ps');
saveas(gcf,'decompinflation2','jpg');


%return
% %% Chart: Core inflation 2
% figure();
% plot(range,d.dot_cpi_x,'LineWidth',3,'color','r','LineStyle','-','Marker','o');
% hold on
% u = [d.b2*d.b3*d.a2*d.a4*(1-d.f1)*d.f2*d.exp_target, ...
%     d.b1*d.dot_cpi_x{-1}+(1 - d.b1)*d.E_dot_cpi_x + d.b2*d.b3*d.a2*d.a4*d.E_dot4_cpi - d.b2*d.b3*d.a2*d.a4*(1-d.f1)*d.f2*d.exp_dot4_cpi,...
%     d.b2*d.b3*d.a1*d.lgdp_gap{-1} + d.b2*d.b3*(1-d.a1)*d.E_lgdp_gap  + d.b2*d.b3*d.a3*d.lx_gdp_gap + d.b2*d.b3*d.e_lgdp_gap - d.b2*d.b3*d.a2*d.a4*(1-d.f1)*d.f3*d.lgdp_gap,...
%     d.b2*d.b3*d.a2*d.a4*d.f1*d.rn{-1}  - d.b2*d.b3*d.a2*d.a4*(1-d.f1)*d.rn_neutral + d.b2*d.b3*d.a2*d.a4*d.rr_eq + d.b2*d.b3*d.a2*(1-d.a4)*d.lz_gap + d.b2*(1-d.b3)*d.lz_gap,...
%     d.e_dot_cpi_x - d.b2*d.b3*d.a2*d.a4*d.e_rn];
% conbarplot(u, range, '');
% hold on
% plot(range,d.dot_cpi_x,'LineWidth',3,'color','r','LineStyle','-','Marker','o');
% h = legend('Actual','Inflation target','Inflation persistence and expectations','Demand pressures','Monetary conditions','Other factors (off-model)');
% colormap('bone');
% grid
% print(gcf,'-dpsc2','decompcoreinflation2.eps');
% orient landscape
% saveas(gcf,'decompcoreinflation2','jpg');

xx.publish('Ghana_SR_box.pdf');

